package com.wc.AlgoOJ_train.train6_图论.最短路.光头强的旅行;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * @Author congge
 * @Date 2024/4/14 16:06
 * @description http://43.138.190.70:8888/p/GR0203
 */
public class Main {
    /**
     * 思路：将到达 n 的最短路路径存下来(错误思路)
     *
     * 正确思路：分情况，用优惠券和不用优惠券
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 510, M = 4010, K = 15;
    static int[][] d = new int[N][N];
    static int[] h = new int[N];
    static int[] ne = new int[M];
    static int[] e = new int[M];
    static int[] w = new int[M];
    // dist[i][j] 表示到达i点用了j张优惠券的最短路
    static int[][] dist = new int[N][K];
    static int idx = 1;
    static int INF = 0x3f3f3f3f;
    static int n, m, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (i == j) d[i][j] = 0;
                else d[i][j] = INF;
            }
        }
        while (m-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
            add(a, b, c);
            add(b, a, c);
        }

        int res = dijkstra();
        out.println(res);
        out.flush();
    }

    static void add(int a, int b, int c) {
        e[idx] = b;
        w[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }

//    static void spfa() {
//        Arrays.fill(dist, 1, n + 1, INF);
//        Queue<Integer> q = new LinkedList<>();
//        dist[1] = 0;
//        q.add(1);
//        st[1] = true;
//        while (!q.isEmpty()) {
//            int t = q.poll();
//            st[t] = false;
//            for (int i = h[t]; i > 0; i = ne[i]) {
//                int j = e[i];
//                if (dist[j] > dist[t] + w[i]) {
//                    pre[j] = t;
//                    dist[j] = dist[t] + w[i];
//                    if (!st[j]) {
//                        q.add(j);
//                        st[j] = true;
//                    }
//                }
//            }
//        }
//    }

    static int dijkstra() {
        for (int i = 1; i <= n; i++) {
            Arrays.fill(dist[i], 0, k + 1, INF);
        }
        PriorityQueue<int[]> q = new PriorityQueue<>(Comparator.comparingInt(o -> o[0]));
        q.add(new int[]{0, 1, 0});
        dist[1][0] = 0;
        while (!q.isEmpty()) {
            int[] a = q.poll();
            int t = a[1];
            int dt = a[2];

            for (int i = h[t]; i > 0; i = ne[i]) {
                int j = e[i];
                // 不用优惠券
                if (dist[j][dt] > dist[t][dt] + w[i]) {
                    dist[j][dt] = dist[t][dt] + w[i];
                    q.add(new int[]{dist[j][dt], j, dt});
                }
                // 用优惠券
                if (dt < k && dist[j][dt + 1] > dist[t][dt] + w[i] / 2) {
                    dist[j][dt + 1] = dist[t][dt] + w[i] / 2;
                    q.add(new int[]{dist[j][dt + 1], j, dt + 1});
                }
            }
        }
        int res = INF;
        for (int i = 0; i <= k; i++) {
            res = Math.min(res, dist[n][i]);
        }
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
